//
//  SimplePromptView.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/8.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "SimplePromptView.h"
@interface SimplePromptView ()
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end
@implementation SimplePromptView

INITFROMXIB

- (void)awakeFromNib{
    [super awakeFromNib];
    //    CGRect frame = self.bgView.bounds;
    //    frame.size.width = SCREEN_WIDTH;
    //    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: frame byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10,10)];
    //      //创建 layer
    //      CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    //      maskLayer.frame = frame;
    //      //赋值
    //      maskLayer.path = maskPath.CGPath;
    self.bgView.layer.cornerRadius = 10.0;
    self.bgView.layer.masksToBounds = YES;
}

- (void)showInView:(UIView *)view{
    [view addSubview:self];
    [self show];
}

- (void)show{
    self.backgroundColor = [UIColor clearColor];
    self.bgView.transform = CGAffineTransformScale(CGAffineTransformIdentity,CGFLOAT_MIN,CGFLOAT_MIN);
    
    [UIView animateWithDuration:0.15
                     animations:^{
        self.bgView.transform = CGAffineTransformIdentity;
        self.backgroundColor = [[UIColor alloc] initWithWhite:0 alpha:0.8];
    }
                     completion:^(BOOL finished) {
     
    }];
    
    
    
    
}

- (void)hide{
    
    [UIView animateWithDuration:0.15
                     animations:^{
        self.backgroundColor = [UIColor clearColor];
        self.bgView.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.1,0.1);
    }
                     completion:^(BOOL finished) {
        [self removeFromSuperview];
     
    }];
    
}
- (IBAction)doneAction:(id)sender {
    if (self.doneBlock) {
        self.doneBlock();
        [self hide];
    }
    [self hide];
    
}

@end
